/*
Copyright (c) 2010 Vadim Seregin
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/


#ifndef DICTLIST_H
#define DICTLIST_H

#include <cstdlib>
#include <wx/wx.h>
#include "wx/wxsqlite3.h"
#include "../../res/dictdialog.h" // Base class: DictDialog
#include "../../res/cardworddialog.h"
#include "wordlist.h"
#include "baselist.h"
#include "dblink.h"

class DictList : public DictDialog, public BaseList
{

public:
	DictList( DbLink* pcDbLink, wxString& soundFileDir );
	~DictList();

	// load dicts
	void Load();
	
	wxString GetTableName(){ return m_sTableName; }
	
protected:
	// get primary language
	wxString GetPrimLang(){ return m_textCtrlPrimLang->GetLineText(0); }
	
	// get translation language
	wxString GetTranLang(){ return m_textCtrlTranLang->GetLineText(0); }
	
	// get dictionary name
	wxString GetDictName(){ return m_textCtrlDictName->GetLineText(0); }
	
	// set primary language
	void SetPrimLang( wxString& str ){ m_textCtrlPrimLang->SetValue( str ); }
	
	// set translation language
	void SetTranLang( wxString& str ){ m_textCtrlTranLang->SetValue( str ); }
	
	// set dictionary name
	void SetDictName( wxString& str ){ m_textCtrlDictName->SetValue( str ); }
	
	// fill list with dicts and return the number of dicts
	long FillDictList( bool bClear = false );
	
	// update item in the list
	void UpdateItem();
	
	// clear text in the TextCtrls
	void ClearText();
	
	// clear info
	void ClearInfo();
	
	// update dir names starting from iNum
	void DirsUpdate( long iNum );

	// ======================== events ================================

	// create or update dict
	virtual void OnOkClick( wxCommandEvent& event );
	
	// cancel button
	virtual void OnCancelClick( wxCommandEvent& event );
	
	// delete dict creation
	virtual void OnDeleteClick( wxCommandEvent& event );
	
	// open dict
	virtual void OnOpenClick( wxCommandEvent& event );
	
	// create dict
	virtual void OnCreateClick( wxCommandEvent& event );
	
	// if list item is selected
	virtual void OnDictSelected( wxListEvent& event );
	
	// if list item is deselected
	virtual void OnDictDeselected( wxListEvent& event );
	
	// left double click
	virtual void OnLeftDClick( wxMouseEvent& event );
	
	// key down
	virtual void OnKeyDown( wxKeyEvent& event );

	// enter window
	virtual void OnEnterWindow( wxMouseEvent& event );
	
protected:
	enum eDict
	{
		eDict_PrimLang = 0,
		eDict_TranLang,	
		eDict_Name,
		eDict_TableName,
		eDict_Words,
		eDict_Cols
	};
	
	wxSQLite3Database *m_pDictDb;   // pointer to dict database
	wxSQLite3Database *m_pCardDb;   // pointer to card database
	wxString m_sPrimLang;           // string for primary language
	wxString m_sTranLang;           // string for translation language
	wxString m_sDictName;           // string for dictionary name
	wxString m_sTableName;          // string for table name
	wxString m_sFileDir;            // string for sound file dir
	long     m_iDictNum;            // number of dicts

	DbLink* m_pcDbLink;             // link to db
};

#endif // DICTLIST_H
